
import {homeData,address} from "../../api/eapi.js"

const pageConfig = ({
  data: {
    orderTotal: 1,
    freight: 1 ,
    homeData:'',
    defaultAddress:null
  },
  /*计算数量*/
  conunt(e) {
    let btntype = e.target.dataset.btntype;
    switch(btntype) {
      case 'up':
        this.setData({freight: this.data.freight + 1});
      break;
      case 'down':
        (this.data.freight > 1) && this.setData({freight: this.data.freight - 1});
      break;
      default: ;  
    }
  },
  
  onLoad: function (options) {
   let ID=options.product,
   _this=this;
  homeData(`drink/${ID}`,{}).then(res=>{
    this.setData({
      homeData:res.data.data
    })
  });


  },
  onShow:function(){
    address.get().then(resp => {
      if (resp.data)
        this.setData({ defaultAddress: resp.data.filter(item => item.default === 1) })
    })
  }
});

/**
 * Redux状态映射函数
 * 
 * @param state redux state对象
 */


Page(pageConfig)
